#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Time    : 2024/6/4 15:05
@Author  : thezehui@gmail.com
@File    : 1.configurable_fields使用技巧.py
"""
import dotenv
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import PromptTemplate
from langchain_core.runnables import ConfigurableField
from langchain_openai import ChatOpenAI

dotenv.load_dotenv()

prompt=PromptTemplate.from_template("请生成一个小于{x}的随机整数")
chat_openai = ChatOpenAI(model="deepseek-r1:70b").configurable_fields(
    temperature=ConfigurableField(
        id="llm_temperature",
    )

)
chain = prompt | chat_openai | StrOutputParser()
chain_with=chain.with_config({"configurable": {"llm_temperature": "0"}})
content=chain_with.invoke({"x": 100})
print(content)